package com.example.game_level;



import java.io.IOException;


import org.andengine.audio.music.Music;
import org.andengine.audio.music.MusicFactory;
import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundFactory;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.font.BitmapFont;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;

import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import org.andengine.util.color.Color;
import org.andengine.util.debug.Debug;











import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.widget.EditText;

import android.widget.TextView;




public class StartActivity extends SimpleBaseGameActivity  {

	
	
	  
	static final int Camera_Width=800;
	static final int Camera_Height=1280;
	public Font mFont,nFont, kFont, hFont,tFont,numFont;
    BitmapFont renderfont;
	public Camera mCamera;
	public String ch;
	public Scene mCurrentScene;
	public static StartActivity instance;
    public int pos;
    public int next_color;
	static final boolean ANTIALIAS_DEFAULT = true;
	static final int COLOR_DEFAULT = Color.WHITE_ABGR_PACKED_INT;
	
	int score;
	int cur_row;
    Blocks bricks_g0[][],bricks[][],bricks_up[][];
    int lev1[],lev[];
    int level=1;
	int phy_position[];
	Letter_Blocks letterblock[];
	GameScene scene;
	
	//String st;
	//EditText mEdit;
	
	int color_key=0; 
	int key[];
	int position[];


	

	public Color u_color1;
	public Color u_color2;
	public Color u_color3;
	public Color u_color4;
	public Color u_color5;
	public Color u_color6;
	public Color u_color7;
	
	String st,str;
	private BitmapTextureAtlas mBitmapTextureAtlas;
	TextureRegion mButtonRegion,mButtonRegion1,mButtonRegion2,mSwarRegion,sha,gya,rie,space,enter,shift,click ;
	TextureRegion mSwarhalant, mSwarka, mSwarki, mSwarkii,mSwarku,mSwarkuu,mSwaraey,mSwaraeyy,mSwarko,mSwarkoo;
	TextureRegion Onea, Oneb, Threea, Threeb, Threec;
	TextView textView;
    EditText mEdit;
	
	 TextureRegion mScoreRegion;
	Music bgmusic;
	Music bgsound;
	Sound collapse1,fall;
	Sound collapse2;
	MediaPlayer mediaPlayer;
	
	
	
	public static StartActivity getSharedInstance(){
    	return instance;
    }
    
    public void setCurrentScene( Scene scene){
    	mCurrentScene=scene;
    	getEngine().setScene(mCurrentScene);
    }
    
    
    	

	@Override
	public EngineOptions onCreateEngineOptions() {
		
		instance = this;
		mCamera = new Camera(0,0,Camera_Width,Camera_Height);
		
		EngineOptions engineOptions = new EngineOptions(true,ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(Camera_Width,Camera_Height),mCamera);
//		engineOptions.setTouchController(new MultiTouchController());
		engineOptions.getAudioOptions().setNeedsSound(true);
		engineOptions.getAudioOptions().setNeedsMusic(true);
		return engineOptions;
	}

	@Override
	protected void onCreateResources() {
//		this.mBitmapFont = new BitmapFont(this.getTextureManager(), this.getAssets(), "font/BitmapFont.fnt");
//		this.mBitmapFont.load();
		
// LOADING THE FONTS		
		mFont= FontFactory.create(this.getFontManager(),this.getTextureManager(),1024,1024,Typeface.create(Typeface.DEFAULT,Typeface.BOLD),60,ANTIALIAS_DEFAULT,COLOR_DEFAULT);
		mFont.load();
		
		nFont= FontFactory.create(this.getFontManager(),this.getTextureManager(),1024,1024,Typeface.create(Typeface.DEFAULT,Typeface.BOLD),45,ANTIALIAS_DEFAULT,COLOR_DEFAULT);
		nFont.load();
		
		tFont= FontFactory.create(this.getFontManager(),this.getTextureManager(),1024,1024,Typeface.create(Typeface.DEFAULT,Typeface.BOLD),40,ANTIALIAS_DEFAULT,COLOR_DEFAULT);
		tFont.load();
		
		final ITexture fontTexture = new BitmapTextureAtlas(this.getTextureManager(),1024,1024);

		hFont = FontFactory.createFromAsset(this.getFontManager(),fontTexture,this.getAssets(),"font/mangal.ttf",45,true,COLOR_DEFAULT);
		hFont.load();
	
		final ITexture numTexture = new BitmapTextureAtlas(this.getTextureManager(),1024,1024);
		numFont= FontFactory.createFromAsset(this.getFontManager(),numTexture,this.getAssets(),"font/mangal.ttf",35,true,COLOR_DEFAULT);
		numFont.load(); 
		
// LOADING THE BACKGROUND/LETTER IMAGES
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        mButtonRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "bg100.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        mButtonRegion1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "bg90.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        mButtonRegion2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "bg80.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Panchachakra.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarhalant = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "halant.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
       
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarka = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ka.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarki = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ki.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarkii = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "kii.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarku = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ku.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarkuu = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "kuu.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwaraey = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ay.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwaraeyy = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "aeyy.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarko = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ko.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
   
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        mSwarkoo = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "koo.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        sha = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "ksha.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        gya = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "gnya.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        rie = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "shra.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        space = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Space_grey.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        shift = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Shift_grey.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        enter = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Return_grey.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
       
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(),1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mScoreRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "score.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);


        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
        click = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Click.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        //transition screens
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
        Onea = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level_1a.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
        Oneb = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level_1b.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
        Threea = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level_3a.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
        Threeb = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level_3b.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
        Threec = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "level_3c.png", 0, 0);
        this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
        
// LOADING THE SOUND AND MUSIC FILES		
        MusicFactory.setAssetBasePath("mfx/");
	     
	     try {
	     	 bgmusic = MusicFactory.createMusicFromAsset(mEngine.getMusicManager(), this, "bgsound7.mp3");
	     	 bgmusic.setVolume(0.5f);
	     	 bgmusic.setLooping(true);
	     } catch (final IOException e) {
	     	Debug.e(e);
	     }
	     
	     SoundFactory.setAssetBasePath("mfx/");

	     try {
	     	 bgsound = MusicFactory.createMusicFromAsset(this.mEngine.getMusicManager(), this, "shift.mp3");
	     	 bgsound.setVolume(0.5f);
	  //   	 bgsound.setLooping(true);
	     } catch (final IOException e) {
	     	Debug.e(e);
	     }
	    
	     try {
	     	 collapse1 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "break.mp3");
	     	 collapse1.setVolume(10); 
	   //  	 mySound.setLooping(true);
	     } catch (final IOException e) {
	     	Debug.e(e);
	     }
	     
	     try {
	     	 collapse2 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "break.mp3");
	   //  	 mySound.play();
	     } catch (final IOException e) {
	     	Debug.e(e);
	     }
	     
	     try {
	     	 fall = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "click.mp3");
	   //  	 mySound.play();
	   //  	 mySound.setLooping(true);
	     } catch (final IOException e) {
	     	Debug.e(e);
	     }
   
	}

	@Override
	protected Scene onCreateScene() {
		// TODO Auto-generated method stub
		mEngine.registerUpdateHandler(new FPSLogger());
		 mCurrentScene =  new MainMenuScene();
		
		 return this.mCurrentScene;
	}
	
	
/*	@Override
	public void onBackPressed() {
	
		super.onBackPressed();
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
	}
	*/
	
	
	
}

